package com.zhanglijie.improve.aqs.aqsandsync;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.SynchronousQueue;
import java.util.zip.DataFormatException;

import javafx.scene.input.DataFormat;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/9/11 0011 14:03
 */
public class SyncRecrusions {
    public synchronized void one(){//recrusion ++
        System.out.println(Thread.currentThread().getName()+"进入one方法"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
        two();
        try{
            Thread.sleep(2000);
        }catch (Exception e){}
        //recrusion --
    }

    private synchronized void two() {//recrusion ++
        System.out.println(Thread.currentThread().getName()+"进入two方法"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
        try{
            Thread.sleep(2000);
        }catch (Exception e){}
        //recrusion --
    }

    public static void main(String[] args) throws InterruptedException {
        SyncRecrusions syncRecrusions = new SyncRecrusions();
        new Thread(()->syncRecrusions.one(),"t1").start();

        new Thread(()->syncRecrusions.two(),"t2").start();
    }
}
